import axios from 'axios'
import QS from 'qs';
import Md5 from 'js-md5';

let time = Math.round(new Date().getTime() / 1000);
let uid = localStorage.getItem("userId");
let token = localStorage.getItem("token");

let baseUrl = '';

// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.defaults.withCredentials = true;
export function get(src, params) {
    let url = baseUrl + src;
    return new Promise((resolve, reject) => {
        axios.get(url, {
            headers: {
                "token": token,
                "uid": uid,
                "time": time
            },
            params: params
        })
            .then(res => {
                console.log(222)                                
                resolve(res);
            })
            .catch(err => {
                reject(err)
            })
    });
}
export function lang(src, params) {
    let url = baseUrl + src;
    return new Promise((resolve, reject) => {
        axios.post(url, QS.stringify(params),)
            .then(res => {
                // console.log(res)
                resolve(res);
            })
            .catch(err => {
                // console.log(err)
                reject(err)
            })
    });
}
export function post(src, params) {
    let url = baseUrl + src;
    return new Promise((resolve, reject) => {
        axios.post(url, QS.stringify(params), {
            headers: {
                "token": Md5(token + uid + time),
                "uid": 1,
                "time": 2222222222222
            },
        })
            .then(res => {
                // console.log(res)
                resolve(res);
            })
            .catch(err => {
                // console.log(err)
                reject(err)
            })
    });
}